﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data;
using PointOfSale.Global;
using CrystalDecisions.Shared; 
using CrystalDecisions.CrystalReports.Engine; 

namespace PointOfSale.Report.Stock
{
	/// <summary>
	/// Summary description for frmReport.
	/// </summary>
	public class frmReportOverStock : System.Windows.Forms.Form
	{		
		public string strDiaDiem = "Quay chinh";		
		string report_file = ""; 		
		string SQL;
		//ReportDocument ReportDoc = new ReportDocument(); 
		ReportDocument crReportDocument = new ReportDocument();
		public static frmReportOverStock clsfrmReport;
		private CrystalDecisions.Windows.Forms.CrystalReportViewer crpViewer; 
		//private CrystalDecisions.Windows.Forms.CrystalReportViewer crpViewer;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmReportOverStock()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		private void makeReport(string ReportFile) 
		{ 

			crReportDocument.Load(ReportFile); 
			//crpViewer.ReportSource = crReportDocument; 
		} 
 
		private ParameterValues AddDiscreteValue (string paramValue, ParameterValues paramValues)
		{
			ParameterDiscreteValue paramDiscreteValue = new ParameterDiscreteValue ();
			paramDiscreteValue.Value = paramValues.Add (paramDiscreteValue);
			return paramValues;
		}
		private void SetParamValue	(string paramName, string paramValue)
		{
			//			for(int i=0;i<crReportDocument.DataDefinition.FormulaFields.Count;  i++)
			//				if(crReportDocument.DataDefinition.FormulaFields[i].FormulaName=="{" + paramName +  "}")
			//					crReportDocument.DataDefinition.FormulaFields[i].Text = "\"" +paramValue +"\"";

			crReportDocument.SetParameterValue(paramName,paramValue);
			//			for(int i=0;i<crReportDocument.DataDefinition.ParameterFields.Count;  i++)
			//				if(crReportDocument.DataDefinition.ParameterFields[i].ParameterFieldName=="{" + paramName +  "}")
			//					crReportDocument.DataDefinition.ParameterFields[i].CurrentValues = "\"" +paramValue +"\"";

		}

		private string GetParamValue	(string paramName)
		{
			string tmpValue="";
			for(int i=0;i<crReportDocument.DataDefinition.FormulaFields.Count;  i++)
			{
				if(crReportDocument.DataDefinition.FormulaFields[i].FormulaName=="{" + paramName +  "}")
					tmpValue= crReportDocument.DataDefinition.FormulaFields[i].Text ;
			}
			return tmpValue;
		}

		private DataColumn CreateNewColumn( string sColumnType, string sColumnCaption,string sColumnName)
		{
			DataColumn dtColumn = new DataColumn();			
			dtColumn.DataType = System.Type.GetType("System." + sColumnType);
			dtColumn.ColumnName = sColumnName;
			dtColumn.Caption = sColumnCaption;			
			dtColumn.AutoIncrement = false;			
			dtColumn.ReadOnly = false;
			dtColumn.Unique = false;
			return dtColumn;
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.crpViewer = new CrystalDecisions.Windows.Forms.CrystalReportViewer();
			this.SuspendLayout();
			// 
			// crpViewer
			// 
			this.crpViewer.ActiveViewIndex = -1;
			this.crpViewer.DisplayGroupTree = false;
			this.crpViewer.Dock = System.Windows.Forms.DockStyle.Fill;
			this.crpViewer.Location = new System.Drawing.Point(0, 0);
			this.crpViewer.Name = "crpViewer";
			this.crpViewer.ReportSource = null;
			this.crpViewer.ShowGroupTreeButton = false;
			this.crpViewer.Size = new System.Drawing.Size(736, 326);
			this.crpViewer.TabIndex = 0;
			// 
			// fromReportOverStock
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(736, 326);
			this.Controls.Add(this.crpViewer);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
			this.Name = "fromReportOverStock";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "Bao cao";
			this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
			this.Load += new System.EventHandler(this.fromReportOverStock_Load);
			this.ResumeLayout(false);

		}
		#endregion

		private void fromReportOverStock_Load(object sender, System.EventArgs e)
		{

			
			
			try
			{
				dsOverStock ds = new dsOverStock();
				SqlCommand _sqlCommand = new SqlCommand("spOverStock", Global.clsGlobal.g_DataConn);
				_sqlCommand.CommandType = CommandType.StoredProcedure;
				

				SqlParameter myParmDepartment = _sqlCommand.Parameters.Add("@DepartmentName", SqlDbType.NVarChar);
				myParmDepartment.Value = strDiaDiem.ToString();
				myParmDepartment.Direction = ParameterDirection.Input;
				System.Data.SqlClient.SqlDataAdapter sda = new System.Data.SqlClient.SqlDataAdapter(_sqlCommand);
				sda.Fill(ds, "spOverStock");
				
				rptOverStock rpt = new rptOverStock();
				rpt.SetDataSource(ds);
				rpt.SetParameterValue("@Thongbao","Thong bao");
				
				this.crpViewer.ReportSource = rpt;
				
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.ToString());
			}
			
			
			
		}		
		
	}
}
